package pl.wroc.pwr.mss.server.ui.menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JMenuItem;

import pl.wroc.pwr.mss.logic.domain.Playlist;
import pl.wroc.pwr.mss.server.service.PlaylistService;
import pl.wroc.pwr.mss.server.ui.tables.JPlaylistTable;
import pl.wroc.pwr.mss.server.ui.tables.models.PlaylistTableModel;

/**
 * Pozycja w menu po ktorej kliknieciu usuniete zostana wszystkie playlisty
 * aktualnie zaznaczone na tabeli playlist.
 * 
 * @author mjagus
 */
public class JRemoveSelectedMenuItem extends JMenuItem implements ActionListener
{
    /**
     * Identyfikator klasy.
     */
    private static final long serialVersionUID = -2052323210298000281L;

    /**
     * Tabela z playlistami.
     */
    private JPlaylistTable playlistTable;

    /**
     * Serwis dla encji Playlist.
     */
    private PlaylistService playlistService;

    /**
     * Iniciuje komponent.
     */
    public JRemoveSelectedMenuItem()
    {
        super("Remove selected");

        super.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e)
    {
        List<Playlist> toRemove = playlistTable.getSelectedPlaylists();
        for(Playlist playlist : toRemove)
            playlistService.remove(playlist);

        ((PlaylistTableModel)playlistTable.getModel()).fireTableDataChanged();
    }

    /**
     * @return Tabela z playlistami
     */
    public JPlaylistTable getPlaylistTable()
    {
        return playlistTable;
    }

    /**
     * @param playlistTable Tabela z playlistami
     */
    public void setPlaylistTable(JPlaylistTable playlistTable)
    {
        this.playlistTable = playlistTable;
    }

    /**
     * @return Serwis dla encji Playlist
     */
    public PlaylistService getPlaylistService()
    {
        return playlistService;
    }

    /**
     * @param playlistService Serwis dla encji Playlist
     */
    public void setPlaylistService(PlaylistService playlistService)
    {
        this.playlistService = playlistService;
    }
}
